import os
import re

file_path = './xmls/'
file_list = os.listdir(file_path)
for file in file_list:
    with open(file_path + file, 'r') as f:
        all_lines = f.readlines()
    with open(file_path + file, 'w+') as f:
        for each_line in all_lines:
            # 先替换right为临时标记
            temp_line = re.sub('right', 'TEMP_MARKER', each_line)
            # 再替换left为right
            a = re.sub('left', 'right', temp_line)
            # 最后将临时标记替换为left
            a = re.sub('TEMP_MARKER', 'left', a)
            f.writelines(a)
    print(f'{file}替换成功！')
print('ALL FINISH!')